﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Diagnostics;

namespace CountdownCalendar.Converters
{
    public class DaysWeeksConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DateTime date;
            ObjectDataProvider odp = parameter as ObjectDataProvider;
            Settings settings = odp.ObjectInstance as Settings;
            if (value != null)
            {
                bool isValid = StringToDateTime.GetDateTime(value.ToString(), out date);
                if (isValid)
                {
                    TimeSpan span = date - DateTime.Now;
                    if (Math.Abs(span.Days) == 0)
                    {
                        if (settings.WeekDaysOnly)
                            return "weekday until";
                        else
                            return "day until";
                    }
                    else
                    {
                        if (settings.WeekDaysOnly)
                            return "weekdays until";
                        else
                            return "day until";
                    }
                }
                else
                    return string.Empty;
            }
            else
                return string.Empty;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
